library(tidyverse)
library(haven)
library(stargazer)

df <- read_dta("CEEW - ACCESS2018.dta")

df <- df %>% select(m2_q55_grid, m1_q20_gender, m1_q19_age, m1_q24_religion, m1_q25_caste, m1_q23_edu, m1_q11_village_code)

df <- df %>% mutate(village = as.factor(m1_q11_village_code))

df$hindu <- df$m1_q24_religion==1

df$scheduled <- df$m1_q25_caste==1 | df$m1_q25_caste==2

df$educated <- df$m1_q23_edu>2

df$female <- df$m1_q20_gender==0

m_full <- lm(m2_q55_grid ~ female + m1_q19_age + hindu + scheduled + educated + village, data=df)

m1 <- lm(m2_q55_grid ~ female + village, data=df)

m2 <- lm(m2_q55_grid ~ m1_q19_age +village, data=df)

m3 <- lm(m2_q55_grid ~ hindu +village, data=df)

m4 <- lm(m2_q55_grid ~ scheduled +village, data=df)

m5 <- lm(m2_q55_grid ~ educated +village, data=df)

stargazer(m_full, m1, m2, m3, m4, m5, 
          type="latex",
          covariate.labels = c("Female Household Head", "Age", "Hindu?", "Scheduled Caste/Tribe?", "High Education?"),
          omit="village",
          omit.stat= c("rsq","ser","f"),
          dep.var.labels = "Uptake of Grid Electricity",
          float=F
)
